package Thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-07-25
 * Time: 14:47
 */

/**
 * 创建线程方法1
 */
class MyThread extends Thread {
    //重写Thread里面的run方法
    @Override
    public void run() {
        //这里写的代码即将创建出的线程,要执行的任务逻辑
        while (true) {
            System.out.println("Hello Thread");
            try {
                Thread.sleep(1000);//方便观察,每打印一次就休息一会
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

public class demo1 {
    public static void main(String[] args) throws InterruptedException {
        MyThread t = new MyThread();
        t.start();//调用start,就会在进程内部,创建一个新的线程,新的线程就会执行我们刚才重写的run里面的代码
        while (true) {
            System.out.println("Hello Main");
            Thread.sleep(1000);
        }
    }
}
